﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace King.BaseUtility
{
    /// <summary>
    /// 
    /// </summary>
    public enum StringCase
    {
        /// <summary>
        /// 大写
        /// </summary>
        UPPER=0X01,

        /// <summary>
        /// 小写
        /// </summary>
        LOWER=0X02,

        /// <summary>
        /// 忽略大小写
        /// </summary>
        SENSITIVE=0X03,
    }

    /// <summary>
    ///  操作类型
    /// </summary>
    public enum OperationType
    {
        /// <summary>
        /// 添加
        /// </summary>
        ADD=0X01,

        /// <summary>
        /// 修改
        /// </summary>
        EDIT=0X02,

        /// <summary>
        /// 删除
        /// </summary>
        DELETE=0X03
    }

    /// <summary>
    /// 配置项
    /// </summary>
    public class CfgItem
    {
        #region Const

        #endregion

        #region Field

        /// <summary>
        /// 编号
        /// </summary>
        public int ID
        {
            get;
            set;
        }

        /// <summary>
        /// 名称
        /// </summary>
        public string Name
        {
            get;
            set;
        }

        /// <summary>
        /// 描述
        /// </summary>
        public string Description
        {
            get;
            set;
        }

        #endregion

        #region Construction

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="id">配置项编号</param>
        /// <param name="name">配置项名称</param>
        /// <param name="description">配置项描述</param>
        public CfgItem(int id,string name,string description="")
        {
            this.ID = id;
            this.Name = name;
            this.Description = description;
        }

        /// <summary>
        /// 克隆一份当前对象
        /// </summary>
        /// <returns>对象副本</returns>
        public new CfgItem Clone()
        {
            return (CfgItem)this.MemberwiseClone();
        }

        #endregion

        #region Static Function

        #endregion

        #region Punlic Function

        #endregion

        #region Assist Function

        #endregion

    }

    /// <summary>
    /// 
    /// </summary>
    public class CfgTable:Dictionary<int,CfgItem>
    {
        #region Const

        #endregion

        #region Field

        /// <summary>
        /// 配置项名称大小写格式
        /// </summary>
        private StringCase m_stringCase;
        public StringCase StringCase
        {
            set
            {
                m_stringCase = value;
            }
            get
            {
                return m_stringCase;
            }
        }

        /// <summary>
        /// 配置项名称最大字符长度
        /// </summary>
        private int m_maxNameLength;
        public int MaxNameLength
        {
            set
            {
                m_maxNameLength = value;
            }
            get
            {
                return m_maxNameLength;
            }
        }

        /// <summary>
        /// 是否允许配置项名称相同
        /// </summary>
        private bool m_isAllowSameName;
        public bool IsAllowSameName
        {
            set
            {
                m_isAllowSameName = value;
            }
            get
            {
                return m_isAllowSameName;
            }
        }

        /// <summary>
        /// 最小ID
        /// </summary>
        private int m_minID;
        public int MinID
        {
            set
            {
                m_minID = value;
            }
            get
            {
                return m_minID;
            }
        }

        /// <summary>
        /// 最大ID
        /// </summary>
        private int m_maxID;
        public int MaxID
        {
            set
            {
                m_maxID = value;
            }
            get
            {
                return m_maxID;
            }
        }

        #endregion

        #region Construction

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="stringCase">配置项大小写格式</param>
        /// <param name="maxNameLength">配置项名称最大字符长度</param>
        /// <param name="isAllowSameName">是否允许配置项名称相同</param>
        /// <param name="minID">最小ID</param>
        /// <param name="maxID">最大ID</param>
        public CfgTable(StringCase stringCase=StringCase.SENSITIVE,int maxNameLength=1024,
                       bool isAllowSameName=false,int minID=0,int maxID=int.MaxValue)
        {
            this.m_stringCase = stringCase;
            this.m_maxNameLength = maxNameLength;
            this.m_isAllowSameName = isAllowSameName;
            if (minID < 0)
                this.m_minID = 0;
            else
                this.m_minID = minID;
            if (maxID <= 0)
                this.m_maxID = int.MaxValue;
            else
                this.m_maxID = maxID;
        }

        #endregion

        /// <summary>
        /// 索引
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public new CfgItem this[int id]
        {
            get
            {
                try
                {
                    return base[id];
                }
                catch
                {
                    return null;
                }
            }
        }

        #region Static Function

        #endregion

        #region Punlic Function


        #endregion

        #region Assist Function



        #endregion
    }
}
